package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import org.apache.logging.log4j.util.Strings;

import java.util.Objects;

public enum OrderQuickStatusEnum implements IEnum<Integer> {

    PENDING(0, "待处理"),
    INVALID(10, "已作废"),
    PROCESSED(20, "已处理");

    private Integer value;

    private String desc;

    OrderQuickStatusEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static String getDesc(Integer status) {
        for (OrderQuickStatusEnum thisEnum : OrderQuickStatusEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum.desc;
            }
        }
        return Strings.EMPTY;
    }

    public static OrderQuickStatusEnum get(Integer status) {
        for (OrderQuickStatusEnum thisEnum : OrderQuickStatusEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum;
            }
        }
        throw Ex.systemError("未定义的订单类型[{}]", status);
    }

    @Override
    public Integer value() {
        return this.value;
    }

    @Override
    public String named() {
        return this.desc;
    }
}
